package jj.rmirm.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import jj.rmirm.manager.RMIManager;

public class PopMenu extends JPopupMenu implements ActionListener {
	
	public PopMenu() {
		this.objName = new JMenuItem("objectName");
		this.objName.setActionCommand(CMD_NAME);
		this.objName.addActionListener(this);
		this.objName.setEnabled(false);
		this.objName.setArmed(false);
		
		this.remove = new JMenuItem("Remove");
		this.remove.setActionCommand(CMD_REMOVE);
		this.remove.addActionListener(this);
		
		this.add(this.objName);
		this.addSeparator();
		this.add(this.remove);
	}
	
	public void setClickedString(String name) {
		this.objName.setText(name);
	}

	@Override
	public void actionPerformed(ActionEvent a) {
		if(a.getActionCommand().equals(CMD_REMOVE)) {
			manager.unbindObject(this.objName.getText());
		}
	}
	
	private static final long serialVersionUID = 9204607054032249012L;
	
	private static final String CMD_NAME = "name";
	private static final String CMD_REMOVE = "remove";
	
	private JMenuItem objName;
	private JMenuItem remove;
	private RMIManager manager = RMIManager.getManager();
}
